package com.begye.smartloan.apptest.ext

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.util.DisplayMetrics
import androidx.core.content.ContextCompat


fun Context.screenWidth(): Int {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        val windowManager = getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
        val bounds = windowManager.currentWindowMetrics.bounds
        bounds.width()
    } else {
        val displayMetrics = DisplayMetrics()
        val windowManager = getSystemService(Context.WINDOW_SERVICE) as android.view.WindowManager
        @Suppress("DEPRECATION")
        windowManager.defaultDisplay.getMetrics(displayMetrics)
        displayMetrics.widthPixels
    }
}

fun Context.checkNotAgreePermissions(list: List<String>?): List<String> {
    if (list.isNullOrEmpty()) return emptyList()

    val notAgreeList = mutableListOf<String>()
    list.forEach {
        if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, it)) {
            notAgreeList.add(it)
        }
    }

    return notAgreeList
}